﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

/*********************************************************
 * 命名空间 Simple.BasicNet.Core.Net
 * 接口名称 ConnectionContext
 * 开发人员：11920
 * 创建时间：2023/4/7 10:11:00
 * 描述说明：
 * 更改历史：
 * 
 * *******************************************************/
namespace Simple.PrettyNet.Handle
{
	public class HandleContext: IContext
	{
		public DataPack CurrentPack { get { return currentPack; } set { currentPack = value; } }

		private DataPack currentPack;
		private Action<byte[]> send;
		public void Send(byte[] bytes)
		{
			send.Invoke(bytes);
		}

		public void SendUTF8(string msg)
		{
			Send(Encoding.UTF8.GetBytes(msg));
		}
		public void SendASCII(string msg)
		{
			Send(Encoding.ASCII.GetBytes(msg));
		}

		internal void SetSend(Action<byte[]> action)
		{
			send=action;
		}

		public TContext GetContext<TContext>() where TContext : class,IContext 
		{
		   if(this is  TContext context)
			{
				return context;
			}
			return null;
		}
	}
}
